﻿using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;

namespace Commnunications
{
    /// <summary>
    /// 管道对象包装类
    /// </summary>
    public abstract class ChannelHandle
    {
        public ChannelHandleType Type { get; private set; }
        public ChannelHandle(ChannelHandleType type)
        {
            this.Type = type;
        }
        /// <summary>
        /// 接收
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public virtual int Receive(byte[] buffer, int len)
        {
            return 0;
        }
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public virtual int Send(byte[] buffer)
        {
            return 0;
        }
        /// <summary>
        /// 判断是否连接ok
        /// </summary>
        public virtual bool IsConnected { get; protected set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ip">ip或串口号</param>
        /// <param name="conTimeout">连接超时;串口时，忽略该参数</param>
        /// <param name="port">串口时，忽略该参数</param>
        /// <param name="readWriteTimeout">tcp 该参数大于0时设定；读写超时</param>
        /// <returns></returns>
        public virtual bool Connect(string ip, int conTimeout = 5000, int port = 0,int readWriteTimeout=5000)
        {
            return false;
        }
        /// <summary>
        /// 关闭连接
        /// </summary>
        public virtual void Close() { }
    }
}
